using System;
using System.Collections.Generic;
using Matrix.Configuration.Domain.Events;

namespace Matrix.Configuration.Events
{
    /// <summary>
    /// 配置变更事件传输对象
    /// </summary>
    public class ConfigurationChangedEto
    {
        /// <summary>
        /// 事件唯一标识
        /// </summary>
        public Guid EventId { get; set; }

        /// <summary>
        /// 配置键
        /// </summary>
        public string Key { get; set; } = string.Empty;

        /// <summary>
        /// 配置命名空间
        /// </summary>
        public string Namespace { get; set; } = string.Empty;

        /// <summary>
        /// 配置分类
        /// </summary>
        public string Category { get; set; } = string.Empty;

        /// <summary>
        /// 旧值
        /// </summary>
        public string? OldValue { get; set; }

        /// <summary>
        /// 新值
        /// </summary>
        public string? NewValue { get; set; }

        /// <summary>
        /// 值类型
        /// </summary>
        public string ValueType { get; set; } = "string";

        /// <summary>
        /// 配置重要性级别
        /// </summary>
        public ConfigurationImportanceLevel Importance { get; set; }

        /// <summary>
        /// 配置变更类型
        /// </summary>
        public ConfigurationChangeType ChangeType { get; set; }

        /// <summary>
        /// 配置变更来源
        /// </summary>
        public ConfigurationChangeSource ChangeSource { get; set; }

        /// <summary>
        /// 变更信息
        /// </summary>
        public ConfigurationChangeInfo ChangeInfo { get; set; } = new();

        /// <summary>
        /// 是否为敏感配置
        /// </summary>
        public bool IsSensitive { get; set; }

        /// <summary>
        /// 配置版本
        /// </summary>
        public int Version { get; set; }

        /// <summary>
        /// 事件发生时间
        /// </summary>
        public DateTime EventTime { get; set; }

        /// <summary>
        /// 租户标识
        /// </summary>
        public Guid? TenantId { get; set; }

        /// <summary>
        /// 源服务名称
        /// </summary>
        public string SourceService { get; set; } = string.Empty;

        /// <summary>
        /// 事件标签
        /// </summary>
        public Dictionary<string, object> Tags { get; set; } = new();

        /// <summary>
        /// 扩展属性
        /// </summary>
        public Dictionary<string, object> Properties { get; set; } = new();
    }

    /// <summary>
    /// 批量配置变更事件传输对象
    /// </summary>
    public class ConfigurationBatchChangedEto
    {
        /// <summary>
        /// 批量事件唯一标识
        /// </summary>
        public Guid BatchEventId { get; set; }

        /// <summary>
        /// 包含的配置变更列表
        /// </summary>
        public List<ConfigurationChangedEto> Changes { get; set; } = new();

        /// <summary>
        /// 批量操作类型
        /// </summary>
        public ConfigurationBatchOperationType OperationType { get; set; }

        /// <summary>
        /// 批量操作原因
        /// </summary>
        public string Reason { get; set; } = string.Empty;

        /// <summary>
        /// 批量操作触发者
        /// </summary>
        public string TriggeredBy { get; set; } = string.Empty;

        /// <summary>
        /// 批量操作来源
        /// </summary>
        public ConfigurationChangeSource ChangeSource { get; set; }

        /// <summary>
        /// 事件发生时间
        /// </summary>
        public DateTime EventTime { get; set; }

        /// <summary>
        /// 租户标识
        /// </summary>
        public Guid? TenantId { get; set; }

        /// <summary>
        /// 源服务名称
        /// </summary>
        public string SourceService { get; set; } = string.Empty;

        /// <summary>
        /// 扩展属性
        /// </summary>
        public Dictionary<string, object> Properties { get; set; } = new();
    }

    /// <summary>
    /// 配置重要性级别
    /// </summary>
    public enum ConfigurationImportanceLevel
    {
        /// <summary>
        /// 低重要性 - 应用配置、UI配置等
        /// </summary>
        Low = 0,

        /// <summary>
        /// 中等重要性 - 缓存配置、日志配置等
        /// </summary>
        Medium = 1,

        /// <summary>
        /// 高重要性 - 业务规则配置、限流配置等
        /// </summary>
        High = 2,

        /// <summary>
        /// 关键重要性 - 数据库连接、安全配置、认证配置等
        /// </summary>
        Critical = 3
    }

    /// <summary>
    /// 配置变更来源
    /// </summary>
    public enum ConfigurationChangeSource
    {
        /// <summary>
        /// 手动更新
        /// </summary>
        ManualUpdate = 0,

        /// <summary>
        /// 批量导入
        /// </summary>
        BatchImport = 1,

        /// <summary>
        /// 系统自动更新
        /// </summary>
        SystemUpdate = 2,

        /// <summary>
        /// 配置同步
        /// </summary>
        ConfigurationSync = 3,

        /// <summary>
        /// API调用
        /// </summary>
        ApiCall = 4,

        /// <summary>
        /// 环境变量更新
        /// </summary>
        EnvironmentVariable = 5,

        /// <summary>
        /// 配置文件更新
        /// </summary>
        ConfigurationFile = 6,

        /// <summary>
        /// 数据库变更
        /// </summary>
        Database = 7
    }

    /// <summary>
    /// 批量配置操作类型
    /// </summary>
    public enum ConfigurationBatchOperationType
    {
        /// <summary>
        /// 批量创建
        /// </summary>
        Create = 0,

        /// <summary>
        /// 批量更新
        /// </summary>
        Update = 1,

        /// <summary>
        /// 批量删除
        /// </summary>
        Delete = 2,

        /// <summary>
        /// 批量导入
        /// </summary>
        Import = 3,

        /// <summary>
        /// 批量导出
        /// </summary>
        Export = 4,

        /// <summary>
        /// 混合操作
        /// </summary>
        Mixed = 5
    }

    /// <summary>
    /// 配置变更信息
    /// </summary>
    public class ConfigurationChangeInfo
    {
        /// <summary>
        /// 变更者ID
        /// </summary>
        public string? ChangedBy { get; set; }

        /// <summary>
        /// 变更者名称
        /// </summary>
        public string? ChangedByName { get; set; }

        /// <summary>
        /// 变更原因
        /// </summary>
        public string Reason { get; set; } = string.Empty;

        /// <summary>
        /// 变更来源IP地址
        /// </summary>
        public string? SourceIpAddress { get; set; }

        /// <summary>
        /// 变更来源用户代理
        /// </summary>
        public string? UserAgent { get; set; }

        /// <summary>
        /// 变更请求ID
        /// </summary>
        public string? RequestId { get; set; }

        /// <summary>
        /// 变更跟踪ID
        /// </summary>
        public string? TraceId { get; set; }
    }
}